package top.forforever.srb.core.controller.api;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.forforever.srb.common.exception.Assert;
import top.forforever.srb.common.result.R;
import top.forforever.srb.common.result.ResponseEnum;
import top.forforever.srb.core.pojo.vo.BorrowerVO;
import top.forforever.srb.core.service.BorrowerService;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Mr.Jiang
 * @since 2023-04-29
 */
@RestController
@RequestMapping("/api/core/borrower")
public class ApiBorrowerController {

    @Autowired
    private BorrowerService borrowerService;

    @GetMapping("getBorrowerStatus")
    public R getBorrowerStatus(HttpServletRequest request) {
        String userId = request.getHeader("userId");
        Assert.notNull(userId, ResponseEnum.LOGIN_AUTH_ERROR);
        Integer borrowerStatus = borrowerService.getBorrowerStatus(userId);
        return R.ok().data("borrowerStatus",borrowerStatus);
    }

    @PostMapping("saveBorrower")
    public R saveBorrower(@RequestBody BorrowerVO borrowerVO, HttpServletRequest request) {
        String userId = request.getHeader("userId");
        Assert.notNull(userId, ResponseEnum.LOGIN_AUTH_ERROR);
        borrowerService.saveBorrower(borrowerVO,userId);
        return R.ok();
    }

}

